import { reqAddressList, reqSubmitOrder, reqtradeList } from "@/api"

export default {
    state: {
        address: [],
        tradeInfo: {},
        orderId:'',
    },
    mutations: {
        SET_ADDRESS(state, data) { 
            state.address=data
        },
        SET_TRADE(state, data) { 
            state.tradeInfo=data
        },
        SET_ORDERID(state, data) { 
            state.orderId = data
        }
    },
    actions: {
        async getAddress({commit}) { 
            let res = await reqAddressList()
            if (res.code == 200) { 
                commit('SET_ADDRESS',res.data)
            }
        },
        async getTrade({commit}) { 
            let res = await reqtradeList()
            if (res.code == 200) { 
                commit('SET_TRADE',res.data)
            }
        },
        async submitOrder({ commit }, { tradeNo, data }) {
            let res = await reqSubmitOrder(tradeNo, data)
            console.log(res);
            if (res.code == 200) { 
                commit('SET_ORDERID',res.data)
                return 'ok'
            }
            return Promise.reject(res.message)
        },
    },
    getters:{}
}